<?php

namespace app\interfaces\model;

use think\Request;
use think\Db;
use think\Model;

class Member extends Model
{

    // 模型事件
    protected static function init()
    {
        // 新增前
        self::event('before_insert', function ($data) {
            $data->username = Request::instance()->param('username');
            $data->password = mcs(Request::instance()->param('password'));
            $data->create_ip = getIP();
            $data->create_time = time();
        });

//        // 新增后
//        self::event('after_insert', function ($data) {
//            // 插入附表
//            Db::name('member_brokerage')->insert(['member_id' => $data->id]);
//            Db::name('member_distribution')->insert(['distribution_id' => '1', 'referrals_id' => $data->id, 'hierarchy' => '0,', 'level' => '1', 'create_time' => time()]);
//        });
    }

}
